package com.woniu.gf.pawn.productentityweb.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.gf.pawn.comm.core.domain.ProductEntity;
import com.woniu.gf.pawn.comm.core.domain.ProductEntityIdentify;
import com.woniu.gf.pawn.dto.IdentifyDto;
import com.woniu.gf.pawn.dto.ProductEntityDto;
import com.woniu.gf.pawn.param.IdentifyParam;
import com.woniu.gf.pawn.param.PageParam;
import com.woniu.gf.pawn.productentityweb.dao.ProductEntityIdentifyMapper;
import com.woniu.gf.pawn.productentityweb.dao.ProductEntityMapper;
import com.woniu.gf.pawn.productentityweb.service.IProductEntityIdentifyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author TL
 * @since 2020-10-14
 */
@Service
public class ProductEntityIdentifyServiceImpl extends ServiceImpl<ProductEntityIdentifyMapper, ProductEntityIdentify> implements IProductEntityIdentifyService {

    @Autowired
    private ProductEntityIdentifyMapper identifyMapper;
    @Autowired
    private ProductEntityMapper entityMapper;

    @Override
    public void addIdentifyProduct(IdentifyParam identifyParam) {
        ProductEntityIdentify identify = new ProductEntityIdentify();
        BeanUtils.copyProperties(identifyParam,identify);
        identify.setProductEntityIdentifyTime(new Date());
        identifyMapper.insert(identify);
        entityMapper.updateById(new ProductEntity().setProductEntityId(identifyParam.getProductEntityId()).setProductEntityStatus("待评估").setIdentifyManId(identifyParam.getIdentifyManId()));
    }

    @Override
    public IPage<IdentifyDto> findIdentifyProduct(PageParam pageParam) {
        Page<IdentifyDto> identifyPage = new Page<>(pageParam.getPageIdx(), pageParam.getPageSize());
        IPage<IdentifyDto> identifyProduct = identifyMapper.findIdentifyProduct(identifyPage,pageParam.getProductEntityId());

        return identifyProduct;
    }
}
